package com.heima.media.controller;

import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.ChannelDto;
import com.heima.media.entity.WmChannel;
import com.heima.media.service.IWmChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Mr_Su
 * @version v1.0
 * @date 2022/6/25 12:31
 * @desciption
 */
@RestController
@RequestMapping("/api/v1/channel")
@Api(tags = "频道管理API")
public class WmChannelController {

    @Autowired
    private IWmChannelService iWmChannelService;

    /**
     * 根据名称模糊查询分页列表
     * @param dto
     * @return
     */
    @PostMapping("/list")
    @ApiOperation(value = "根据频道名称模糊查询分页频道列表", notes = "author:Su")
    @ApiImplicitParam(name = "dto",value = "查询对象",dataType = "ChannelDto",required = true)
    public ResponseResult listByName(@RequestBody ChannelDto dto){
        return iWmChannelService.listByName(dto);
    }

    @PostMapping
    @ApiOperation(value = "新增频道", notes = "author:Su")
    @ApiImplicitParam(name = "wmChannel",value = "频道",dataType = "WmChannel",required = true)
    public ResponseResult addWmChannel(@RequestBody WmChannel wmChannel){
        return iWmChannelService.addWmChannel(wmChannel);
    }

    @GetMapping("/channels")
    @ApiOperation(value = "channels",notes = "查询所有频道")
    public ResponseResult channels(){
        List<WmChannel> list = iWmChannelService.list();
        return ResponseResult.okResult(list);
    }
}
